package com.demo.java.spring.ioc;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

public class BeanFactoryAwareTest implements BeanFactoryAware {
    private static BeanFactory beanFactory;

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("bean factory aware, set bean factory");
        BeanFactoryAwareTest.beanFactory = beanFactory;
    }

    public static void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        System.out.println("custom register bean definition");
        ((DefaultListableBeanFactory)BeanFactoryAwareTest.beanFactory).registerBeanDefinition(beanName, beanDefinition);
    }
}
